<style type="text/css" title="currentStyle">
	@import "../media/css/demo_page.css";
	@import "../media/css/demo_table_jui.css";
	@import "../examples_support/themes/smoothness/jquery-ui-1.8.4.custom.css";
	@import "media/css/TableTools_JUI.css";
</style>
<script type="text/javascript" charset="utf-8" src="../media/js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8" src="media/js/ZeroClipboard.js"></script>
<script type="text/javascript" charset="utf-8" src="media/js/TableTools.js"></script>
<script type="text/javascript" charset="utf-8">
	$(document).ready( function () {
		$('#example').dataTable( {
			"bJQueryUI": true,
			"sPaginationType": "full_numbers",
			"sDom": 'Tlfrtip',	
			"oTableTools": {
				"aButtons": [
					"copy", "csv", "xls", "pdf", "print",
					{
						"sExtends":    "collection",
						"sButtonText": "Save",
						"aButtons":    [ "csv", "xls", "pdf" ]
					}
				]
			}
		} );
	} );
</script>
<script language="javascript">
function funEditUser(uid,cid,act)
{
	document.frmSubmit.txtDeviceId.value = uid;
	document.frmSubmit.txtClientId.value = cid;
	document.frmSubmit.action = act;
	document.frmSubmit.submit();
}
</script>

<div align="left" class="listofusers">&nbsp;<a href="#" onclick="funEditUser('','<?php echo $_POST[txtClientId];?>','?ch=addClientDevice')">Add New Device</a></div>

<table cellpadding="0" cellspacing="0" border="0" class="gridform_final" id="example">      
	<thead>
    <tr>
		<th width="5%">#</th>
        <th width="12%">Device ID   </th>
        <th width="14%">Device Name </th>
        <th width="14%">Client Name</th>
        <th width="15%">IMEI</th> 
        <th width="8%">Mobile No</th>
        <th width="9%">Device Model</th>
        <th width="7%">Status</th>
        <th width="7%">Edit</th>
        <th width="15%">Subscription</th>
   </tr>
    </thead>
   <tbody>
   <?php
   if(isset($_POST[txtClientId]))
   		$clientID = $_POST[txtClientId];
	else
		$clientID = $_SESSION[clientID];
		
   $sql = "SELECT * FROM tb_deviceinfo,tb_clientinfo WHERE ci_id = di_clientId AND di_clientId =".$clientID." ORDER BY di_deviceId DESC";

   $rows = $db->query($sql);
   if($db->affected_rows > 0)
   {
   $i = 1;
   	while ($record = $db->fetch_array($rows)) 
	{
		
		if($record[di_deviceModel] > 0)
		{
			$sql1 = "SELECT * FROM tb_device_model WHERE id = ".$record[di_deviceModel];
			$rows1 = $db->query($sql1);
			if($db->affected_rows > 0)
			{
				$deviceModelRecord = $db->fetch_array($rows1);
				$devModel = $deviceModelRecord[tdm_aliasName];
			}			
		}else $devModel = "Not Selected";
	?>
		<tr>
		<td><?php echo $i;?></td>
        <td><?php echo ucfirst($record[di_deviceId]);?></td>
        <td><?php echo $record[di_deviceName];?></td>
        <td><?php echo ucfirst($record[ci_clientName]);?></td>
        <td><?php echo $record[di_imeiId];?> </td> 
        <td><?php echo $record[di_mobileNo];?> </td>
        <td><?php echo ucfirst($devModel);?></td>
         <td><?php if($record[di_status]=='1'){echo 'Active';}else {echo 'In Active';}?></td>
        <td><img src="../../images/edit.gif" style="cursor:pointer;" width="45" height="16" border="0" onclick="funEditUser('<?php echo $record[di_id];?>','<?php echo $_POST[txtClientId];?>','?ch=addClientDevice')" /></td>
        <td><img src="../../images/view.gif" style="cursor:pointer;" width="45" height="16" border="0" onclick="funEditUser('<?php echo $record[di_id];?>','<?php echo $_POST[txtClientId];?>','?ch=viewSubscription')" /></td>
   </tr>
    <?php
		$i++;
	}
	}
   ?>
   </tbody>
</table>
</div>
</div>
</div>
<form name="frmSubmit" id="frmSubmit" method="post">
	<input type="hidden" name="txtDeviceId" id="txtDeviceId" />
    <input type="hidden" name="txtClientId" id="txtClientId" />
</form>